package com.ityuwen.mengyagushi.account.service.impl;

import com.ityuwen.mengyagushi.account.mapper.RechargeInfoMapper;
import com.ityuwen.mengyagushi.account.service.RechargeInfoService;
import com.ityuwen.mengyagushi.common.constant.SystemConstant;
import com.ityuwen.mengyagushi.common.util.AuthContextHolder;
import com.ityuwen.mengyagushi.model.account.RechargeInfo;
import com.ityuwen.mengyagushi.vo.account.RechargeInfoVo;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class RechargeInfoServiceImpl extends ServiceImpl<RechargeInfoMapper, RechargeInfo> implements RechargeInfoService {

	@Autowired
	private RechargeInfoMapper rechargeInfoMapper;

	@Override
	public Map<String, Object> submitRecharge(RechargeInfoVo rechargeInfoVo) {
		RechargeInfo rechargeInfo = new RechargeInfo();
		rechargeInfo.setRechargeStatus(SystemConstant.ORDER_STATUS_UNPAID);
		rechargeInfo.setRechargeAmount(rechargeInfoVo.getAmount());
		rechargeInfo.setPayWay(rechargeInfoVo.getPayWay());
		rechargeInfo.setUserId(AuthContextHolder.getUserId());
		rechargeInfo.setOrderNo(IdWorker.getIdStr());
		this.save(rechargeInfo);

		Map<String, Object> map = new HashMap<>();
		map.put("orderNo", rechargeInfo.getOrderNo());
		return map;
	}
}
